package com.moon.game.command.guest.lair;

import java.util.List;

import com.moon.game.command.BaseCmd;
import com.moon.game.command.RequestSession;
import com.moon.game.constants.ErrorCode;
import com.moon.game.exception.GException;
import com.moon.game.vos.ErrorMsg;
import com.moon.game.vos.PlayerVo;
import com.moon.game.vos.PlayerVo.Pet;

/**
 * @description 查看指定宠物详细信息
 * @author Ranger 作者 E-mail:haozi000005@163.com
 * @version 创建时间：2012-7-23 上午10:01:41
 */
public class ShowPetDetailCmd extends BaseCmd{

	@Override
	protected void runOnce(RequestSession req) throws GException {
		switch (req.getStatus()) {
			case STATU_INIT:
				doInit(req);
				break;
			case STATU_CHECK:
				doCheckSelf(req);
				break;
			case STATU_RETURN:
				doResponse(req);
				break;
			default:
				break;
		}		
	}

	@Override
	protected void doResponse(RequestSession req) throws GException {
		String[] ps = req.getClientRequest().getPs();
		if (ps == null) {
			doResponsePsError(req);
			return;
		}
		
		Integer playerPetId = Integer.parseInt(ps[0]);
		PlayerVo player = req.getPlayer();
		List<Pet> pets = player.getPetList();
		Pet thePet = null;
		boolean hasThePet = false;
		if (pets != null) {
			for (Pet pet : pets) {
				if (pet.getPlayerPetId() == playerPetId) {
					hasThePet = true;
					thePet = pet;
					break;
				}
			}
		}
		
		if (!hasThePet) {
			//如果查看的宠物不存在返回错误
			doResponseErrorMsg(req, ErrorMsg.build(ErrorCode.ERR_NO_PET, "你要查看的宠物不存在！"));
			return;
		}

		req.setVO("pet", thePet);
		response(req, req.getClientResponse());
	}

}
